第四章也蠻簡單的,Böhm與Jacopini證明所有程式都可使用三種流程控制表達
簡單的來看就是if else , switch, for, while, do while,while與do while差別只在於一個先做再判斷一個先判斷在做,來改寫一下前面的setCourseName方法讓兩個if變成if..else
void GradeBook::setCourseName( string name )
{
if ( name.length() <= 25 ) // if name has 25 or fewer characters
courseName = name; // store the course name in the object
else
{
courseName = name.substr( 0, 25 ); // start at 0, length of 25
cout << "Name \"" << name << "\" exceeds maximum length (25).\n"
<< "Limiting courseName to first 25 characters.\n" << endl;
}
}